package com.chenfan.process.entity.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * @author K
 * @date 2021/2/24 模板创建参数
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApprovalTemplateDTO {

    @ApiModelProperty("节点数据")
    private List<NodeData> nodeDataArray;

    @ApiModelProperty("节点关系数据")
    private List<LinkData> linkDataArray;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class NodeData {
        @ApiModelProperty("类别 Start End")
        private String category;

        @ApiModelProperty("类别说明")
        private String text;


        @ApiModelProperty("节点标签")
        private String tag;

        @ApiModelProperty("节点key")
        private Long key;

        @ApiModelProperty("节点前端唯一key")
        private Long uniq;

        @ApiModelProperty("节点ID")
        private Long processId;

        @ApiModelProperty("选项")
        private List<Option> option;

        @ApiModelProperty("审批人员")
        private List<Audit> auditList;

        @ApiModelProperty("抄送人员")
        private List<CarbonCopy> carbonCopyList;

        @ApiModelProperty("消息模板列表")
        private List<MessageTemplate> messageTemplateList;

        @ApiModelProperty(value = "坐标信息")
        private String loc;

        @ApiModelProperty(value = "url")
        private String url;

        @ApiModelProperty(value = "类型")
        private Integer type;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LinkData {
        @ApiModelProperty("起始节点")
        private Long from;
        @ApiModelProperty("终点")
        private Long to;
        @ApiModelProperty("判断条件名称")
        private String text;
        @ApiModelProperty("关联关系")
        private List<List<LinkDataAttribute>> attributes;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            LinkData linkData = (LinkData) o;
            return Objects.equals(attributes, linkData.attributes);
        }

        @Override
        public int hashCode() {
            return Objects.hash(attributes);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class LinkDataAttribute {
        @ApiModelProperty("表单属性id")
        private String formAttributeId;
        @ApiModelProperty("类型 0-小于 1-小于等于 2-等于 3-大于 4-大于等于 5-不等于")
        private Integer type;
        @ApiModelProperty("值")
        private String values;
        @ApiModelProperty("key值,字段名称")
        private String key;
        @ApiModelProperty("关联关系 0-且(and) 1-或(or)")
        private Integer relation;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            LinkDataAttribute that = (LinkDataAttribute) o;
            return formAttributeId.equals(that.formAttributeId) && type.equals(that.type) && values.equals(that.values);
        }

        @Override
        public int hashCode() {
            return Objects.hash(formAttributeId, type, values);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Audit {

        /**
         * 人员类型
         * 0-普通 1-或签 2-会签 、
         * -1部门负责人 -2空节点 -3指定人员 -4流程创建人
         *
         */
        private Integer type;

        /**
         * 用户id
         */
        private String userId;

        /**
         * 用户名
         */
        private String userName;

        /**
         * 节点标题
         */
        private String processTitle;

        public boolean grouped() {
            return  type == 1 || type == 2;
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CarbonCopy {
        /**
         * 人员类型 -1 流程所有人
         */
        private Integer type;

        /**
         * 用户id
         */
        private Long userId;

        /**
         * 用户名
         */
        private String userName;

        private String url;

        public boolean isALl() {
            return Objects.equals(type, -1) && Objects.isNull(userId);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Option {

        /**
         * 表单属性idmin
         */
        private String id;

        /**
         * 字段值
         */
        private String fieldValues;
        /**
         * 是否必填
         */
        private Boolean required;

        /**
         * 是否可编辑
         */
        private Boolean editable;

        /**
         * 表单id
         */
        private String formId;

        /**
         * 字段类型
         */
        private String fieldType;

        /**
         * 字段名称
         */
        private String fieldName;

        /**
         * 字段Key
         */
        private String fieldKey;
    }

    @Data
    public static class MessageTemplate {

        /**
         * 消息类型
         */
        private String messageType;

        /**
         * 消息类性值
         */
        private String messageTypeValue;

        /**
         * 模板值
         */
        private String messageKey;

        /**
         * 消息模板标题
         */
        private String messageTitle;


    }
}
